package wiki.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import wiki.generic.io.Element;
import wiki.setup.Setup;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 * Responsabile dei paragrafi contenuti nelle pagine
 */
public class ParagraphChooseServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession ses=req.getSession(false);
		if(ses!=null){
			boolean isDoc = (Boolean) ses.getAttribute("rights");
			if(isDoc){
		PrintWriter out=resp.getWriter();
		String type=req.getParameter("type");
		out.write("<html>\n");
		out.write("<head>\n");
		if(type.equals("p")){
			out.write("<title>Paragrafo esistente</title>\n");
		}
		if(type.equals("h3")){
			out.write("<title>Titolo esistente</title>\n");
		}
		out.write("<link rel='stylesheet' type='text/css' href='./html/edit/paragrafoesistente.css' />\n");
		out.write("<script type='text/JavaScript' src='./html/edit/paragrafoesistente.js'></script>\n");
		out.write("</head>\n");
		out.write("<body>\n");
		out.write("<div id='title'>\n");
		if(type.equals("p")){
		out.write("Inserisci Paragrafo gi&agrave; esistente\n");
		}
		if(type.equals("h3")){
			out.write("Inserisci Titolo gi&agrave; esistente\n");
			}
		out.write("</div>\n");
		out.write("<div id='container'>\n");
		out.write("<form action='./editing?scelta="+type+"' method='post' id='modulo' name='modulo'>\n");
		out.write("<table>\n");
		out.write("<div id='show_message'>I seguenti campi sono obbligatori*:</div>\n");
		out.write("<tr>\n");
		out.write("<td class='col1'>Nome<span id='star_nome'>*</span>:&nbsp;&nbsp;&nbsp;<input class='testo' type='text' name='nome' value=''/></td>\n");
		out.write("</tr>\n");
		out.write("</table>\n");
		out.write("<input type='submit' value='Aggiungi' id='bottone' name='submit' onclick=\"if(controllaVuoti('modulo','star_nome','show_message')!=true){return false;}\" />");
		out.write("<h3 id='h3Color'>Scegli:</h3>\n");
		out.write("<div>\n");
		out.write("<ul>\n");
		
		HashMap<Integer, Element> map=Setup.getSetup().getMediator().getVservice().getElementsMapbyType(type);
		Set<Integer> keys=map.keySet();
		if(map.size()==0){
			resp.sendRedirect("./html/errorpages/notestoesistente.html");
		}
		int i=0;
		for (Iterator<Integer> iterator = keys.iterator(); iterator.hasNext();) {
			Integer ID =iterator.next();
			out.write("<li><input type='radio' value='"+ID+"' name='cont' checked='checked'/><p class='");
			if(i%2==0){
				out.write("par1");
			} else {
				out.write("par2");
			}
			
				out.write("'>"+map.get(ID).getInfo()+" <em style='font-size:10px'>["+map.get(ID).getOwner()+"]</em></p></li>\n");
				i++;
		}
		out.write("</ul>\n");
		out.write("</div>\n");
		out.write("<br/>\n");
		out.write("<div id='style-contents'><h3 id='h3Color'>Colore:</h3>\n");
		out.write("<table id='color-table'>\n");
		out.write("<tr>\n");
		out.write("<td><div id='yellow'><input type='radio' class='color' value='color:#FF0;' name='color' /></div></td>\n");
		out.write("<td><div id='orange'><input type='radio' class='color' value='color:#F60' name='color' /></div></td>\n");
		out.write("<td><div id='red'><input type='radio' class='color' value='color:#F00' name='color' /></div></td>\n");
		out.write("<td><div id='pink'><input type='radio' class='color' value='color:#F9C' name='color' /></div></td>\n");
		out.write("<td><div id='violet'><input type='radio' class='color' value='color:#93F' name='color' /></div></td>\n");
		out.write("<td><div id='blue'><input type='radio' class='color' value='color:#03C' name='color' /></div></td>\n");
		out.write("<td><div id='light-blue'><input type='radio' class='color' value='color:#00CCFF' name='color' /></div></td>\n");
		out.write("<td><div id='light-green'><input type='radio' class='color' value='color:#3F0' name='color' /></div></td>\n");
		out.write("<td><div id='green'><input type='radio' class='color' value='color:#090' name='color' /></div></td>\n");
		out.write("<td><div id='black'><input type='radio' class='color' value='color:#000' name='color' checked='checked'/></div></td>\n");
		out.write("</tr>\n");
		out.write("</table>\n");
		out.write("</div>\n");
		if(type.equals("p")){
		out.write("<h3 id='h3Color'>Dimensione Font:</h3>\n");
		out.write("<select name='font-size'>\n");
		out.write("<option value='font-size:14px'>14</option>\n");
		out.write("<option value='font-size:16px'>16</option>\n");
		out.write("<option value='font-size:18px'>18</option>\n");
		out.write("<option value='font-size:20px'>20</option>\n");
		out.write("<option value='font-size:22px'>22</option>\n");
		out.write("<option value='font-size:24px'>24</option>\n");
		out.write("</select>\n");
		}
		if(type.equals("h3")){
			out.write("<h3 id='h3Color'>Dimensione Font:</h3>\n");
			out.write("<select name='font-size'>\n");
			out.write("<option value='font-size:20px'>20</option>\n");
			out.write("<option value='font-size:22px'>22</option>\n");
			out.write("<option value='font-size:24px'>24</option>\n");
			out.write("<option value='font-size:26px'>26</option>\n");
			out.write("<option value='font-size:28px'>28</option>\n");
			out.write("<option value='font-size:30px'>30</option>\n");
			out.write("</select>\n");
		}
		out.write("<br/>\n");
		out.write("<br/>\n");
		out.write("<h3>Font:</h3>\n");
		out.write("<ul id='fontstyle-list'>\n");
		out.write("<li><input type='radio' class='stile' value='font-family:Verdana' name='font' checked='checked'/><span style='font-family:Verdana'>Verdana</span></li>\n");
		out.write("<li><input type='radio' class='stile' value='font-family:Arial' name='font'/><span style='font-family:Arial'>Arial</span></li>\n");
		out.write("<li><input type='radio' class='stile' value='font-family:Tahoma' name='font'/><span style='font-family:Tahoma'>Tahoma</span></li>\n");
		out.write("</ul>\n");
		out.write("<h3>Font-Style:</h3>\n");
		out.write("<ul id='fontstyle-list'>\n");
		out.write("<li><input type='radio' class='stile' value='font-style:italic' name='stile'/><em>Italic</em></li>\n");
		out.write("<li><input type='radio' class='stile' value='font-style:normal' name='stile' checked='checked'/>Normal</li>\n");
		out.write("</ul>\n");
		out.write("<h3>Font-Weight:</h3>\n");
		out.write("<ul id='fontstyle-list'>\n");
		out.write("<li><input type='radio' class='stile' value='font-weight:bold' name='weight'/><strong>Bold</strong></li>\n");
		out.write("<li><input type='radio' class='stile' value='font-weight:normal' name='weight' checked='checked'/>Normal</li>\n");
		out.write("</ul>\n");
		out.write("<h3>Text Decoration:</h3>\n");
		out.write("<ul id='fontstyle-list'>\n");
		out.write("<li><input type='radio' class='stile' value='text-decoration:overline' name='dec'/><span style='text-decoration:overline'>Overline</span></li>\n");
		out.write("<li><input type='radio' class='stile' value='text-decoration:underline' name='dec'/><u>Underline</u></li>\n");
		out.write("<li><input type='radio' class='stile' value='text-decoration:line-through' name='dec'/><span style='text-decoration:line-through'>Sbarrato</span></li>\n");
		out.write("<li><input type='radio' class='stile' value='text-decoration:none' name='dec' checked='checked'/>Normal</li>\n");
		out.write("</ul>\n");
		out.write("<h3>Text-Align:</h3>\n");
		out.write("<ul id='fontstyle-list'>\n");
		out.write("<li><input type='radio' class='stile' value='text-align:center' name='al'/>Center</li>\n");
		out.write("<li><input type='radio' class='stile' value='text-align:justify' name='al'/>Justify</li>\n");
		out.write("<li><input type='radio' class='stile' value='text-align:left' name='al'/>Left</li>\n");
		out.write("<li><input type='radio' class='stile' value='text-align:right' name='al'/>Right</li>\n");
		out.write("</ul>\n");
		out.write("<input type='submit' value='Aggiungi' id='bottone' name='submit' onclick=\"if(controllaVuoti('modulo','star_nome','show_message')!=true){return false;}\" /></form></div></body></html>");
			} else{
				resp.sendRedirect("./html/errorpages/nopermessi.html");
			}
		} else{
			resp.sendRedirect("./html/LOGIN/login.html");
		}
		
		
	}
	
}
